package Chapter12;
public class demo02 {
    public static void main(String[] args) {
        final Object lock = new Object();
        Thread student1 = new Thread(() -> {
            try {
                synchronized (lock) {
                    lock.wait(10 * 60 * 1000); // Wait for 10 minutes
                }
                System.out.println("Student 1准备好了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        Thread student2 = new Thread(() -> {
            try {
                Thread.sleep(60 * 60 * 1000); // Sleep for 1 hour
                synchronized (lock) {
                    System.out.println("Student 2: 醒了");
                    lock.notify(); // Notify teacher thread
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        Thread teacher = new Thread(() -> {
            synchronized (lock) {
                try {
                    for (int i = 0; i < 3; i++) {
                        System.out.println("Teacher: 开始上课！");
                        Thread.sleep(1000);
                    }
                    System.out.println("Teacher: Student 1快醒来!");
                    lock.notify(); // Notify student1 thread
                    System.out.println("Student 1：醒了!");
                    System.out.println("Student 1：Student 2 快醒来!!");
                    lock.wait();
                    student2.start();
                    lock.wait(); // Wait for student2 to be ready
                    System.out.println("Student1 ：Student 2 醒了!");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        teacher.start();
        student1.start();
        student2.start();
    }
}